package com.tuling.JUC;

import jdk.jfr.DataAmount;

import java.util.HashSet;
import java.util.Objects;

public class Email {


    public static void main(String[] args) {

        HashSet<Email> emailSet = new HashSet();

        Email email = new Email("yy.com","Tom");

        emailSet.add(email);

        email.setAddress("xyz.com");

        System.out.println(emailSet.contains(email));

        emailSet.remove(email);

        for(Email email1 : emailSet){

            System.out.println(email1.getAddress());

            System.out.println(email1.getName());

        }

    }
    private String address;

    private String name;

    public Email(String address, String name) {
        this.address = address;
        this.name = name;
    }

    @Override

    public int hashCode() {

        return Objects.hash(address,name);

    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override

    public boolean equals(Object obj) {

        if(obj instanceof Email){

            Email that = (Email) obj;

            return Objects.equals(this.address,that.address) &&

                    Objects.equals(this.name,that.name);

        }

        return false;

    }

}


